package com.ly.mpayment.persist.service.channelbase;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.ChannelBase;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class ChannelBaseServiceImpl extends AbstractService<ChannelBase, Serializable> implements IChannelBaseService {

	@Override
	public ChannelBase saveChannel(ChannelBase base) {
		if(base != null){
			this.save(base);
			return base;
		}
		return null;
	}

	@Override
	public ChannelBase updateChannel(ChannelBase base) {
		if(base != null){
			this.updateEntity(base);
			return base;
		}
		return null;
	}

	@Override
	public Page<ChannelBase> findPageChannel(Map<String, Object> parameter, int start, int pageSize) {
		String hql = "select c from ChannelBase c left join fetch c.operatorsBase where 1 = 1 #[and c.baseName like :baseName]# #[and c.operatorsBase.operatoruid = :operatoruid]# order by c.baseName";
		return this.findPageByNamed(hql, parameter, start, pageSize);
	}

	@Override
	public ChannelBase findById(String baseId) {
		return this.findUnique("select c from ChannelBase c left join fetch c.operatorsBase  where c.baseId = ? ", baseId);
	}

	@Override
	public List findByChannel(String operatoruid) {
		return this.find("select c from ChannelBase c where c.operatorsBase.operatoruid = ?", operatoruid);
	}

	@Override
	public List findAllChannel() {
		return this.find("select distinct  basePrice from ChannelBase c order by  basePrice ");
	}

	@Override
	public boolean deleteChannel(ChannelBase base) {
		this.delete(base) ;
		return true;
	}
}
